<template>
  <a-card :bordered="false">
    <div class="card-title">{{ $route.meta.title }}</div>
    <div class="table-operator">
      <!-- 搜索板块 -->
      <a-row class="row-item-search">
        <a-form class="search-form" :form="searchForm" layout="inline" @submit="handleSearch">
          <a-form-item label="经销商昵称/订单号">
            <a-input v-decorator="['search']" placeholder="请输入经销商昵称/订单号" />
          </a-form-item>
          <a-form-item label="充值方式">
            <a-select v-decorator="['recharge_type', { initialValue: 0 }]">
              <a-select-option :value="0">全部</a-select-option>
              <a-select-option
                v-for="(item, index) in RechargeTypeEnum.data"
                :key="index"
                :value="item.value"
              >{{ item.name }}</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="支付状态">
            <a-select v-decorator="['pay_status', { initialValue: 0 }]">
              <a-select-option :value="0">全部</a-select-option>
              <a-select-option :value="10">待审核</a-select-option>
              <a-select-option :value="20">已通过</a-select-option>
			  <a-select-option :value="30">已拒绝</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="付款时间">
            <a-range-picker format="YYYY-MM-DD" v-decorator="['betweenTime']" />
          </a-form-item>
          <a-form-item class="search-btn">
            <a-button type="primary" icon="search" html-type="submit">搜索</a-button>
          </a-form-item>
        </a-form>
      </a-row>
    </div>
    <s-table
      ref="table"
      rowKey="order_id"
      :loading="isLoading"
      :columns="columns"
      :data="loadData"
      :pageSize="15"
    >
      <!-- 经销商信息 -->
      <span slot="user" slot-scope="data">
		<div v-if="data.real_name">
			<div class="user-info clearfix">
			 <div class="in-left">
			   <a-tooltip>
			      <p class="user-name oneline-hide">经销商ID: {{ data.user.user_id }}</p>
					<!-- <template slot="title">姓名: {{ users.nick_name }}</template> -->
					<p class="user-name oneline-hide">姓名: {{ data.real_name ? data.real_name : data.user.nick_name }}</p>
					<p class="user-name oneline-hide">电话: {{ data.user.mobile }}</p>
			     <!-- <img v-if="user.user.avatar_url.length" :src="user.user.avatar_url" alt="经销商头像" />
			      <img v-else src="~@/assets/img/default-avatar.png" alt="经销商头像" /> -->
			    </a-tooltip>
			  </div>
			  <!-- <div class="in-right flex flex-dir-column flex-x-center"> -->
			    <!-- <p class="user-name oneline-hide">{{ user.real_name ? user.real_name : user.nick_name }}</p> -->
			   <!-- <p class="user-platform">
			      <platform-icon :name="user.platform" :showTips="true" />
			    </p> -->
			  <!-- </div> -->
			</div>
		</div>
		<div v-else>
			<UserItem :user="data.user" />
		</div>
      </span>
      <!-- 套餐名称 -->
      <span slot="order_plan" slot-scope="text">
        <a-tag v-if="text">{{ text.plan_name }}</a-tag>
        <span v-else>--</span>
      </span>
      <!-- 充值方式 -->
      <span slot="recharge_type" slot-scope="text">
        <a-tag>{{ RechargeTypeEnum[text].name }}</a-tag>
      </span>
      <!-- 状态 -->
      <span slot="is_desc_auth" slot-scope="text">
        <a-tag v-if="text == 1 " color="green">已通过</a-tag>
		<a-tag v-if="text == 2 " color="red">已拒绝</a-tag>
		<a-tag v-if="text == 0 " >待审核</a-tag>
      </span>
	  <span class="status" slot="status" slot-scope="item">
	    <a-tag color="green" v-if="item.pay_status == 20 && item.is_agree == 1">已通过</a-tag>
	    <a-tag color="red" v-if="(item.remark != '' && item.pay_status == 10 && item.is_agree == 0) || item.pay_status == 30 || item.is_agree == 2 || item.is_desc_auth == 2" >已拒绝</a-tag>
		<a-tag v-if="item.remark == '' && item.pay_status == 10  || item.is_agree == 0">待审核</a-tag>
	  </span> 
      
      <!-- 操作 -->
      <span class="actions" slot="action" slot-scope="item">
        <a v-if="item.remark == '' && item.pay_status == 10  || item.is_agree == 0 || item.is_desc_auth == 2" title="审核" v-action:recharge @click="handleRecharge(item)">审核</a>
      </span>
    </s-table>
       <AuditForm ref="AuditForm" @handleSubmit="handleRefresh" />
  </a-card>
</template>

<script>
import * as Api from '@/api/user/recharge'
import { STable, UserItem } from '@/components/Table'
import PayStatusEnum from '@/common/enum/recharge/order/PayStatus'
import RechargeTypeEnum from '@/common/enum/recharge/order/RechargeType'
import {AuditForm } from '../modules'

export default {
  name: 'Index',
  components: {
    STable,
    UserItem,
    AuditForm
  },
  data () {
    return {
      // 枚举类
      PayStatusEnum,
      RechargeTypeEnum,
      // 当前表单元素
      searchForm: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 正在加载
      isLoading: false,
      // 表头
      columns: [
        {
          title: 'ID',
          dataIndex: 'order_id'
        },
        {
          title: '经销商信息',
          // dataIndex: 'user',
          scopedSlots: { customRender: 'user' }
        },
        {
          title: '代理级别',
          dataIndex: 'grade_name'
        },
        {
          title: '订单号',
          dataIndex: 'order_no'
        },
        {
          title: '充值方式',
          dataIndex: 'recharge_type',
          scopedSlots: { customRender: 'recharge_type' }
        },
        {
          title: '套餐名称',
          dataIndex: 'order_plan',
          scopedSlots: { customRender: 'order_plan' }
        },
        {
          title: '支付金额',
          dataIndex: 'pay_price'
        },
        // {
        //   title: '赠送金额',
        //   dataIndex: 'gift_money'
        // },
		{
		  title: '扣款人审核',
		  dataIndex: 'is_desc_auth',
		  scopedSlots: { customRender: 'is_desc_auth' }
		},
        {
          title: '平台审核',
          // dataIndex: 'status',
          scopedSlots: { customRender: 'status' }
        },
        {
          title: '付款时间',
          dataIndex: 'pay_time'
        },
        {
          title: '创建时间',
          dataIndex: 'create_time'
        },
        {
          title: '操作',
          // dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: param => {
        return Api.order({ ...param, ...this.queryParam })
          .then(response => {
            return response.data.list
          })
      }
    }
  },
  created () {

  },
  methods: {

    /**
     * 刷新列表
     * @param Boolean bool 强制刷新到第一页
     */
    handleRefresh (bool = false) {
      this.$refs.table.refresh(bool)
    },

    // 确认搜索
    handleSearch (e) {
      e.preventDefault()
      this.searchForm.validateFields((error, values) => {
        if (!error) {
          this.queryParam = { ...this.queryParam, ...values }
          this.handleRefresh(true)
        }
      })
    },
    // 审核
    handleRecharge (item) {
	  this.$nextTick(()=>{
		this.$refs.AuditForm.handle(item)
	  });
    },

  }
}
</script>

<style lang="less" scoped>
.ant-card-body {
  padding: 22px 29px 25px;
}
</style>
